package com.example.fmgidsprototype.data;

import android.database.sqlite.SQLiteDatabase;
import android.provider.BaseColumns;
import android.util.Log;

import com.example.fmgidsprototype.data.CategoryTable.CategoryColumns;
import com.example.fmgidsprototype.data.VenueTable.VenueColumns;

public class VenueReviewTable {
	
	public static final String TABLE_NAME = "VenueReview";
	
	public static class ReviewColumns implements BaseColumns{
		public static final String VENUE = "venue";
		public static final String COMMENT = "comment";
		public static final String DATE_CREATED = "datecreated";
		public static final String USER_NAME = "username";
	}
	
	public static void onCreate(SQLiteDatabase db){
		StringBuilder sb = new StringBuilder();
		sb.append("create table if not exists " + VenueReviewTable.TABLE_NAME + " (");
		sb.append(BaseColumns._ID + " integer primary key, ");
		sb.append(ReviewColumns.VENUE + " integer not null, ");
		sb.append(ReviewColumns.COMMENT + " text not null, ");
		sb.append(ReviewColumns.DATE_CREATED + " numeric unique not null, ");
		sb.append(ReviewColumns.USER_NAME + " text not null, ");
		sb.append("foreign key(" + ReviewColumns.VENUE + ") references ");
		sb.append(VenueTable.TABLE_NAME + "(" + VenueColumns.JSON_ID + ")");
		sb.append(")");
		Log.d("REVIEWCREATE", sb.toString());
		db.execSQL(sb.toString());
	}
	
	public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
		db.execSQL("drop table if exists " + CategoryTable.TABLE_NAME);
		onCreate(db);
	}

}
